﻿using System.Linq.Expressions;

namespace Entropy.Ext
{
    [JsClass("Ext.grid.Panel", "gridpanel")]
    public interface IGridPanel : IPanelTable
	{
	}

    [JsClass("Ext.grid.plugin.EditingView", "editing")]
    public interface IGridEditorPlugin : IAbstractPlugin
    {

    }

    [JsClass("Ext.AbstractPlugin", null)]
    public interface IAbstractPlugin : IBase
    {
    }

    [JsClass("Ext.data.Model", null)]
    public interface IModel
    {
        /// <summary>
        /// Returns the value of the given field
        /// Available since: Ext 1
        /// </summary>
        /// <param name="fieldName">String
        ///  The field to fetch the value for</param>
        /// <returns>Object
        /// The value</returns>
        object get(string fieldName);
    }

    [JsClass("Ext.data.TreeModel", null)]
    public interface ITreeModel : IModel
    {
        INodeInterface data { get; }
    }

    public class EditEvent
    {
        /// <summary>
        /// The grid
        /// </summary>
        public IGridPanel grid;
        
        /// <summary>
        /// The record being edited
        /// </summary>
        public IModel record;

        /// <summary>
        /// The field name being edited
        /// </summary>
        public string field;
        
        /// <summary>
        /// The value for the field being edited.
        /// </summary>
        public object value;

        /// <summary>
        /// The grid table row
        /// </summary>
        public int row;

        /// <summary>
        /// The grid Column defining the column that is being edited.
        /// </summary>
        public int column;

        /// <summary>
        /// The row index that is being edited
        /// </summary>
        public int rowIdx;

        /// <summary>
        /// The column index that is being edited
        /// </summary>
        public int colIdx;

        /// <summary>
        /// Set this to true to cancel the edit or return false from your handler.
        /// </summary>
        public bool cancel;

        /// <summary>
        /// Alias for value (only when using CellEditing).
        /// </summary>
        public object originalValue;

    }
    public delegate bool GridBeforeEdit(EditEvent e, object eOpt, IGridEditorPlugin editor);

    [JsClass("Ext.panel.TableView", "tablepanel")]
    public interface IPanelTable : IPanelPanel
    {
        Expression<GridBeforeEdit> beforeedit { get; set; }
		/// <summary>
		/// Returns the selection model being used and creates it via the configuration if it has not been created already.
		/// Available since: Ext 4
		/// Returns  Ext.selection.Model
		/// </summary>
		/// <returns></returns>
	    ISelectionModel getSelectionModel();
    }
}